import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;


public class SocketTest {

	public static void main(String[] args) {
		Socket socket = null;
		try {
			socket = new Socket("127.0.0.1",4700);
			BufferedReader bufr = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			PrintWriter out = new PrintWriter(socket.getOutputStream());
			
			int count = 0;
			while(true){
				System.out.println(count + "===" + System.currentTimeMillis() / 1000);
				if(count >10){
					out.println("bye");
					out.flush();
				}else{
					out.println("aaaaaaaa"+ "===" + System.currentTimeMillis() / 1000);
					out.flush();
				}
				//System.out.println(bufr.readLine());
				count++;
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			
//			BufferedReader bufr_system_in = new BufferedReader(new InputStreamReader(System.in));
//			String clientMeg = bufr_system_in.readLine();
//			while(!"bye".equals(clientMeg)){
//				out.print(clientMeg);
//				out.flush();
//				System.out.println("Client:" + clientMeg + "\n");
//				System.out.println("Server:" + bufr.readLine() + "\n");
//				clientMeg = bufr_system_in.readLine();
//			}
			
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			System.out.println("shut down........................");
			try {
				socket.close();
			} catch (IOException e) {
				e.printStackTrace();
			}finally{
				socket = null;
			}
		}
	}

}
